// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'

// 饿了么组件
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

import App from './App'
import Vuex from 'vuex'
import router from './router'
import axios from 'axios'


//引入样式
import '@/styles/base/reset.css'


//引入jquery
import $ from 'jquery'

import store from './store'
import {getToken} from '@/utils/auth'
//import '@/utils/plug'

 Vue.use(ElementUI)


 Vue.use(Vuex)
 Vue.prototype.$http = axios
 Vue.config.productionTip = false

axios.defaults.baseURL="/lec";
router.beforeEach((to, from, next) => {
	console.log(to.meta,1)
	if(getToken()){ //是否登陆
        //教师权限
        if(getToken() == 2){
            if(to.meta.role == 2){
                next();
            }
            else{
                next('/LectureList');
            }
        }
        else{
		    next();
        }
		window.document.title = to.meta.title

    }else {
		let flag = to.matched.some(item => item.meta.requireAuth);
        console.log(to.matched,4445);
		if(flag){
            next('/login');
		}else{
			next()
			window.document.title = to.meta.title
		}
		// 调用方法
		// store.dispatch('GetInfo')
        // window.document.title = to.meta.title

    }
})
/* eslint-disable no-new */
new Vue({
  el: '#app',
  store,
  router,
  components: { App },
  template: '<App/>'
})
